package com.ship.contract.config;

import com.ship.common.core.utils.Threads;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.apache.tomcat.util.threads.TaskThreadFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

/**
 * @author 31463
 */
@Configuration
public class ThreadPoolConfig {

    /**
     *核心线程数
     */
    private Integer corePoolSize = 3;

    /**
     * 最大线程数
     */
    private Integer maximumPoolSize = 6;

    /**
     * 线程空闲时间
     */
    private Long keepAliveTime = 60L;

    /**
     * 队列数
     */
    private Integer workQueue = 1000;

    /**
     * 线程名称前缀
     */
    private String namePrefix = "zjxj-cbdd-contract-export";


    @Bean
    public ExecutorService initExecutorService(){
        ExecutorService executorService = new ThreadPoolExecutor(corePoolSize,maximumPoolSize,keepAliveTime,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(workQueue),
                new TaskThreadFactory(namePrefix,true,1));
        return executorService;
    }

}
